package mercurius.fitness.client.rb.user;

import java.util.ArrayList;
import java.util.Date;
import mercurius.fitness.client.locale.Locale;
import net.pleso.framework.client.bl.rb.columns.impl.RBColumn;
import net.pleso.framework.client.dal.IDataColumn;
import net.pleso.framework.client.dal.IDataRow;
import net.pleso.framework.client.dal.db.IDBValue;
import net.pleso.framework.client.dal.db.types.DBDate;
import net.pleso.framework.client.dal.db.types.DBFloat;
import net.pleso.framework.client.dal.db.types.DBInteger;
import net.pleso.framework.client.dal.db.types.DBString;
import net.pleso.framework.client.dal.impl.DataColumn;

public class User extends UserInfo implements IDataRow {
	
	public User() {
		
	}
	
	public User(Integer id, 
			String user,
			String firstname,
			String lastname,
			Date dob,
			Integer hr_max,
			Float vo2_max,
			Integer gender,
			Float height,
			String height_unit,
			String feedkey,
			String adminfeedkey) {
		super( id, 
				user,
				firstname,
				lastname,
				dob,
				hr_max,
				vo2_max,
				gender,
				height,
				height_unit,
				feedkey,
				adminfeedkey);
	}
	
	public class id_column extends Columns {
		public id_column() {
			super("id", "User ID", false);
		}
		
		public IDBValue getCell(User row) {
			return new DBInteger(row.getID());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setID(((DBInteger) value).getInteger());
		}
	}
	
public class user_column extends Columns {
		
		public user_column() {
			super("user", Locale.constants().user(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString(row.getUser());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setUser(((DBString) value).getString());
		}
	}	

	
	public class firstname_column extends Columns {
		
		public firstname_column() {
			super("firstname", Locale.constants().user_firstname_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString(row.getFirstName());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setFirstName(((DBString) value).getString());
		}
	}	
	
	public class lastname_column extends Columns {
		
		public lastname_column() {
			super("lastname", Locale.constants().user_lastname_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString(row.getLastName());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setLastName(((DBString) value).getString());
		}
	}
	
	public class height_column extends Columns {
		
		public height_column() {
			super("height", Locale.constants().user_height_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBFloat(row.getHeight());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setHeight(((DBFloat) value).getFloat());
		}
	}
	
	
	public class heightunit_column extends Columns {
		
		public heightunit_column() {
			super("height_unit", Locale.constants().user_height_unit_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString(row.getHeightUnit());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setHeightUnit(((DBString) value).getString());
		}
	}
	
	
	public class gender_column extends Columns {
		
		public gender_column() {
			super("gender", Locale.constants().user_gender_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBInteger(row.getGender());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setGender(((DBInteger) value).getInteger());
		}
	}
	
	public class dob_column extends Columns {
		
		public dob_column() {
			super("dob", Locale.constants().user_dob_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBDate(row.getDob());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBDate)
				row.setDob(((DBDate) value).getDate());
		}
	}
	
	public class hrmax_column extends Columns {
		
		public hrmax_column() {
			super("hr_max", Locale.constants().user_hrmax_column(), true);
		}
		
		public IDBValue getCell(User row) {
			return new DBInteger(row.getHRMax());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setHRmax(((DBInteger) value).getInteger());
		}
	}

	public class vo2max_column extends Columns {
	
		public vo2max_column() {
			super("vo2_max", Locale.constants().user_vo2max_column(), true);
		}
		
		public IDBValue getCell(User row) {
			return new DBFloat(row.getVo2Max());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setVo2Max(((DBFloat) value).getFloat());
		}
	}
	
	public class feedkey_column extends Columns {
		
		public feedkey_column() {
			super("feed_key", Locale.constants().user_feedkey_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString(row.getFeedkey());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setFeedkey(((DBString) value).getString());
		}
	}


	public class adminfeedkey_column extends Columns {
		
		public adminfeedkey_column() {
			super("adminfeed_key", Locale.constants().user_adminfeedkey_column(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString(row.getAdminFeedkey());
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setAdminFeedkey(((DBString) value).getString());
		}
	}
	
public class newfeedkey_column extends Columns {
		
		public newfeedkey_column() {
			super("newfeedkey", Locale.constants().user_generate_feedkey(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString("2");
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setFeedkey(((DBString) value).getString());
		}
	}


	public class newadminfeedkey_column extends Columns {
		
		public newadminfeedkey_column() {
			super("newadminfeedkey", Locale.constants().user_generate_adminfeedkey(), false);
		}
		
		public IDBValue getCell(User row) {
			return new DBString("2");
		}
		
		public void setCell(User row, IDBValue value) {
			if (value instanceof DBString)
				row.setAdminFeedkey(((DBString) value).getString());
		}
	}
	
	private static ArrayList columns = new ArrayList();
	private static final User instance = new User();
	
	public static RBColumn[] getColumns() {
		RBColumn[] rbColumns = new RBColumn[] {
				new RBColumn(User.Columns.id, 30),
				new RBColumn(User.Columns.user, 30),
				new RBColumn(User.Columns.firstname, 30),
				new RBColumn(User.Columns.lastname, 30)
		};
		return rbColumns;
	}
	
	public abstract static class Columns extends DataColumn {
		
		public Columns(String name, String caption, boolean allowNull) {
			super(name, caption, allowNull);
			columns.add(this);
			this.order = columns.size(); 
		}
		
		
		public abstract void setCell(User row, IDBValue value);
		public abstract IDBValue getCell(User row);public static final id_column id = instance.new id_column();
		public static final user_column user = instance.new user_column();
		public static final firstname_column firstname = instance.new firstname_column();
		public static final lastname_column lastname = instance.new lastname_column();
		public static final dob_column dob = instance.new dob_column();
		public static final hrmax_column hrmax = instance.new hrmax_column();
		public static final vo2max_column vo2max = instance.new vo2max_column();
		public static final gender_column gender = instance.new gender_column();
		public static final height_column height = instance.new height_column();
		public static final heightunit_column heightunit = instance.new heightunit_column();
		public static final feedkey_column feedkey = instance.new feedkey_column();
		public static final adminfeedkey_column adminfeedkey = instance.new adminfeedkey_column();
		public static final newfeedkey_column newfeedkey = instance.new newfeedkey_column();
		public static final newadminfeedkey_column newadminfeedkey = instance.new newadminfeedkey_column();
	}
	
	
	
	
	
	public IDBValue getCell(IDataColumn column) {
		Columns col = (Columns) column;
		return col.getCell(this);
	}
	
	public IDataColumn getColumn(int index) {
		return (IDataColumn) columns.get(index);
	}
	
	public int getColumnCount() {
		return columns.size();
	}
	
	public void setCell(IDataColumn column, IDBValue value) {
		Columns col = (Columns) column;
		col.setCell(this, value);
	}
	
}
